package com.china.produce.config;

import com.china.produce.pojo.City;
import com.china.produce.pojo.People;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/1/19
 */
@Configuration
public class ConditionalOnBeanConfig {

    /**
     * bean 默认单列（spring 加载时候会初始化,调用时候不会再执行）、原型模式（调用几次会执行）
     * @return
     */
    @Bean
    public City city()
    {
        System.out.println("this is city 2");

        City city = new City();

        city.setCode("400");

        city.setName("nanjing");

        return city;
    }

    /**
     * @Lazy spring初始化时候不会执行，调用时候执行一次
     * @param city
     * @return
     */
    @Bean
    @Lazy
    public People peoples(City city)
    {
        System.out.println("bd 存在 ！！@");

        city.setName("shshh");

        city.setCode("1001");

        return new People();
    }

}
